const units = [1000000000, 1000000, 1000];

const unitsMap = ['b', 'm', 'k'];

export const formatBigNum = (num) => {
  for (let i = 0, l = units.length; i < l; i++) {
    if (num >= units[i]) {
      return `${num / units[i]}${unitsMap[i]}`;
    }
  }

  return num;
};

export const formatTag = (item, index, type) => {
  let tagObj = {}
  switch (type) {
    case 'rank':
      tagObj.isShow = index <= 2
      tagObj.desc = index <= 2 ? `TOP ${index + 1}` : null
      break;
    case 'car':
      tagObj.isShow = true
      tagObj.desc = false ? '黑名单':'陌生车辆'
      break;
    case 'face':
      tagObj.isShow = true
      tagObj.desc = true ? '黑名单' : ''
      break;
    case 'img':
      tagObj.isShow = true
      tagObj.desc = '默认'
      break;
    default:
      break;
  }

  return tagObj;
};